<template>
  <section class="grandson mg-t12">
    <p>value inject: {{ random }}</p>
    <p>value inject2: {{ random2.value }}</p>
    <p>grandson: {{ fromGrand }}</p>
    <el-button type="success" @click="getRandom2" class="mg-t12">我是grandson1,获取祖先的值</el-button>
  </section>
</template>
<script>
export default {
  name: 'ChildOne',
  inject: ['getRandom', 'random', 'random2'],
  data () {
    return {
      fromGrand: null
    }
  },
  created () {
    console.log('getRandom: ', this.getRandom())
  },
  methods: {
    getRandom2 () {
      this.fromGrand = this.getRandom()
      if (!this.fromGrand) {
        this.$message('请先在上层组件获取数据')
      }
    }
  }
}
</script>
<style lang="less" scoped>

</style>
